/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulateurs.model.scheduler;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Lunesco
 */
public class Horloge {
	private long startTime; 
	private long endTime; 
	private long scaleTime;
	private long tempsAttente;
	private int fps;
	
	public Horloge(int fps){
		this.fps=fps;
		this.scaleTime=1000/fps;
	}
	
	public void next(){
		
		try {
			Thread.sleep(this.tempsAttente);
		} catch (InterruptedException ex) {
			Logger.getLogger(Horloge.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	public void setEndTime() {
		this.endTime = System.currentTimeMillis();
		this.tempsAttente=this.scaleTime-(this.endTime-this.startTime);
	}

	public void setStartTime() {
		this.startTime = System.currentTimeMillis();
	}

	public long getTempsAttente() {
		return tempsAttente;
	}
	
	public void accelerer(){
		
            this.fps+=5;
		this.scaleTime=1000/(this.fps);
	}
	
	public void ralentir(){
	if(fps>5){	
            this.fps-=5;
		this.scaleTime=1000/(this.fps);}
	}
}
